from django.db import models
from utils.models import BaseModel


class Gate(BaseModel):
    is_using = models.BooleanField(
        verbose_name='是否启用',
        default=False
    )
    sketch = models.CharField(
        verbose_name='入口图片概述',
        max_length=96,
        null=True,
        blank=True,
    )
    left = models.ImageField(
        verbose_name='左侧入口图片',
        upload_to='pic/gate/',
        null=True,
        blank=True,
    )
    right = models.ImageField(
        verbose_name='右侧入口图片',
        upload_to='pic/gate/',
        null=True,
        blank=True,
    )
    left_b = models.ImageField(
        verbose_name='左侧背面入口图片',
        upload_to='pic/gate/',
        null=True,
        blank=True,
    )
    right_b = models.ImageField(
        verbose_name='右侧背面入口图片',
        upload_to='pic/gate/',
        null=True,
        blank=True,
    )

    def __str__(self):
        if self.is_using:
            state = '启用'
        else:
            state = '未启用'
        return state

    class Meta:
        verbose_name_plural = '主页入口图片表'


class BackGround(BaseModel):
    order = models.IntegerField(
        verbose_name='展示顺序',
        default=999999
    )
    sketch = models.CharField(
        verbose_name='背景图片概述',
        max_length=96,
        null=True,
        blank=True,
    )
    pic = models.ImageField(
        verbose_name='背景图片',
        upload_to='pic/background/',
        null=True,
        blank=True,
    )

    def get_url(self):
        return 'http://139.224.58.43:8003/media/' + str(self.pic)

    def __str__(self):
        return '展示顺序<{}>'.format(self.order)

    class Meta:
        verbose_name_plural = '主页背景图片表'
